<div class="box box-skin">
	<div class="box-header with-border">
		<span class="box-title">网站信息</span>
		<div class="box-tools pull-right">
			<button type="button" class="btn btn-flat btn-box-tool btnCancel"
				data-widget="remove">
				<i class="fa fa-times"></i>
			</button>
		</div>
	</div>
	<div class="box-body">
	<form class="form-horizontal" id="settingForm">
		<div class="nav-tabs-custom no-margin">
			<ul class="nav nav-tabs">
				<li class="active">
					<a href="#c1" data-toggle="tab" aria-expanded="true">网站信息</a>
				</li>
				<li class="">
					<a href="#c2" data-toggle="tab" aria-expanded="false">SEO设置</a>
				</li>
			</ul>
			<div class="tab-content">
				<div class="tab-pane active" id="c1">
					<div class="row">
						<div class="col-sm-7">
							<div class="form-group">
								<label for="siteName" class="col-sm-2 control-label">网站名称<span class="text-red">*</span></label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="siteName" name="site_name" placeholder="名称">
								</div>
							</div>
							<div class="form-group">
								<label for="siteTheme" class="col-sm-2 control-label">模版主题</label>
								<div class="col-sm-10">
									<select class="form-control" id="siteTheme" name="site_theme">
									</select>
								</div>
							</div>
							<div class="form-group">
								<label for="siteEmail" class="col-sm-2 control-label">站长邮箱</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="siteEmail" name="site_email" placeholder="站长邮箱">
								</div>
							</div>
							<div class="form-group">
								<label for="siteRecord" class="col-sm-2 control-label">备案信息</label>
								<div class="col-sm-10">
									<textarea class="form-control" rows="6" id="siteRecord" name="site_record" placeholder="备案信息"></textarea>
								</div>
							</div>
							<div class="form-group">
								<label for="siteCopyright" class="col-sm-2 control-label">版权信息</label>
								<div class="col-sm-10">
									<textarea class="form-control" rows="6" id="siteCopyright" name="site_copyright" placeholder="版权信息"></textarea>
								</div>
							</div>
							<div class="form-group">
								<label for="siteStatistics" class="col-sm-2 control-label">统计代码</label>
								<div class="col-sm-10">
									<textarea class="form-control" rows="6" id="siteStatistics" name="site_statistics" placeholder="统计代码"></textarea>
								</div>
							</div>
						</div>
						<div class="col-sm-5">
							<div class="foo">
								<p class="text-muted">1. 图片的尺寸为800*450</p>
								<p class="text-muted">2. 标题根据页面是否显示而确定是否需要填入</p>
								<p class="text-muted">3. 背景颜色主要用于轮播图片</p>
								<p class="text-muted">4. 排序越小，实际显示越靠前</p>
								<p class="text-muted">5. 链接地址可填入本系统的网站或课程链接地址（格式为wx/<path>.do）或其它任意可访问网址
								</p>
								<p class="text-muted">6. 图片说明根据页面是否显示而确定是否需要填入</p>
							</div>
						</div>
					</div>
				</div>
				<div class="tab-pane" id="c2">
					<div class="row">
						<div class="col-sm-7">
							<div class="form-group">
								<label for="siteSeoTitle" class="col-sm-2 control-label">SEO标题</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="seoTitle" name="site_seo_title" placeholder="SEO标题" />
								</div>
							</div>
							<div class="form-group">
								<label for="siteSeoKeywords" class="col-sm-2 control-label">SEO关键字</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="seoKeywords" name="site_seo_keywords" placeholder="SEO关键字" />
								</div>
							</div>
							<div class="form-group">
								<label for="siteSeoDescription" class="col-sm-2 control-label">SEO描述</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="siteSeoDescription" name="site_seo_description" placeholder="SEO描述" />
								</div>
							</div>
						</div>
						<div class="col-sm-5"></div>
					</div>
				</div>
			</div>
		</div>
	</form>
	</div>
	<div class="box-footer text-center">
		<button type="button" class="btn btn-info btn-flat btnOK">确定</button>
		<!-- <button type="button" class="btn btn-default btn-flat btnCancel">取消</button> -->
	</div>
</div>

<script type="text/javascript">
$(function() {
	var url = "{:U('Setting/Setting/findOne')}";
	var obj = kk.getObj(url);
	
	$('#settingForm').setForm(obj);
	initTemplate(obj);
	
	var validator = $("#settingForm").validate({
		onfocusout: function(element) {
			$(element).valid();
		},
        rules: {
        	name: "required",
        },
        messages: {
        	name: "请输入标题",
        }
    });
	
	$('.btnOK').off('click').on('click', function() {
 		if (validator.form() && doCU()) {
			alert("SAVE OK");
 		}
	});
});

/* Create & Update */
function doCU() {
    var url;
    var method;
    var jsonObj = $('#settingForm').serializeObject();
	var jsonStr = JSON.stringify(jsonObj);
//console.log('jsonStr = ' + jsonStr);
	var result;
	
	url = "{:U('Setting/Setting/saveOne')}";
	method = "POST";
	result = kk.doStrAjax(url, method, jsonStr);
	
    if (result.code != 0) {
    	alert(result.msg);
    	return false;
	}
	
	return false;
}

/****** initTemplate ******/
function initTemplate(obj) {
	var url = "{:U('Asset/Template/getAllTheme4Admin')}";
	var themeList = kk.getObj(url);
	
	var str = '';
	for (var i in themeList) {
		str += '<option value="' + themeList[i] + '">' + themeList[i] + '</option>';		// '.html'可能需要从后台获取
	}
	$("#siteTheme").append(str);
	
	// set
	if (obj) {
		$("#siteTheme").val(obj.site_theme);
	}
}
</script>